package cn.undertow.demo.controller;

import cn.hutool.core.util.IdUtil;
import cn.undertow.demo.model.SleepRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/web")
@Slf4j
public class WebController {

    /**
     * 测试undertow超过配置的最大线程时，如何处理
     *
     * @param request
     * @return
     * @throws InterruptedException
     */
    @GetMapping("/sleep")
    public String sleep(SleepRequest request) throws InterruptedException {
        String chainId = IdUtil.simpleUUID();
        log.info("{} 接收到请求: {}", chainId, request);
        Thread.sleep(request.getTime());
        log.info("{} 执行完成", chainId);
        return "success";
    }
}
